<?php
include_once(dirname(__FILE__) . "/../../configure/configure.php");		//--> global var
include_once(dirname(__FILE__) . "/../configure/admin.config.inc.php");	//--> admin global var
include_once(dirname(__FILE__) . "/../tools/smarty/libs/Smarty.class.php");					//--> out template

require_once(dirname(__FILE__) . "/../controlHeader.php");					//--> system control header
require_once(dirname(__FILE__) . "/../controlOperate.php");				//-->

include_once("impl/ImageImpl.php");
include_once("utils/FileUtils.php");

	
$imgImpl 	= new ImageImpl(DB_TAG_MM);
$fileUtils	= new FileUtils();											//--> Files

if(isset($_GET['id']) && !empty($_GET['id'])){
	$id = $_GET['id'];

	$imageDto = $imgImpl->getById($id);
	
	$isOk = $imgImpl->delete($id);
	if($isOk){
		$path = FileUtils::getFullPathByID(IMAGE_PATH_CONTENT, $imageDto->id, $imageDto->id . '.' . $imageDto->extName);
	
		if (file_exists($path)) {
			unlink($path);
			
		}
			
		$error_message = 'delete successfully.';
	}else 
		$error_message = 'delete failure.';
}


echo "<script language='javascript'>";
echo "alert(\"$error_message\");";
echo "location.href=\"".$_SERVER['HTTP_REFERER']."\";";
echo "</script>";

//$backurl = $_SERVER['HTTP_REFERER'];
//header("Location: $backurl");
?>
